<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('活动列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>当前期数：</label>
                                <input type="text" name="num"/>
                            </li>
                            <li>
                                <label style="width: 100px;">活动总积分：</label>
                                <input type="text" name="allIntegral"/>
                            </li>
                            <li>
                                <label style="width: 160px;">参与一次所需积分：</label>
                                <input type="text" name="integral"/>
                            </li>
                            <li>
                                <label>总次数：</label>
                                <input type="text" name="allPeople"/>
                            </li>
                            <li>
                                <label style="width: 140px;">当前已参与次数：</label>
                                <input type="text" name="people"/>
                            </li>
                            <li>
                                <label>中奖人：</label>
                                <input type="text" name="userName"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
               <!-- <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="whzj:activity:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="whzj:activity:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>-->
                <!--<a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="whzj:activity:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>-->
                <!--<a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="whzj:activity:export">
                    <i class="fa fa-download"></i> 导出
                </a>-->
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('whzj:activity:edit')}]];
        var removeFlag = [[${@permission.hasPermi('whzj:activity:remove')}]];
        var prefix = ctx + "whzj/activity";

        $(function() {
            var options = {
                url: prefix + "/list",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "活动",
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: '活动id',
                    visible: false
                },
                {
                    field: 'num',
                    title: '当前期数'
                },
                {
                    field: 'allIntegral',
                    title: '内含有多少积分 默认5000'
                },
                {
                    field: 'integral',
                    title: '参与一次所需积分 默认50'
                },
                {
                    field: 'allPeople',
                    title: '总次数'
                },
                {
                    field: 'people',
                    title: '当前已参与次数'
                },
                {
                    field: 'userName',
                    title: '中奖人昵称'
                },
                    {
                        field: 'status',
                        title: '状态'
                    },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];

                     /*   if(row.status == '保存'){
                            actions.push('<a class="btn btn-warning btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="activityBegin(\'' + row.id + '\')"><i class="fa fa-edit"></i>活动开始</a> ');
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                            actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        }else*/
                      if(row.status == '待开奖'){
                            if(row.allPeople == row.people){
                                if(row.userName != null){
                                    actions.push('<a class="btn btn-info btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="activityEnd(\'' + row.id + '\')"><i class="fa fa-edit"></i>开奖</a> ');
                                }else{
                                    actions.push('<a class="btn btn-warning btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="settingWin(\'' + row.id + '\')"><i class="fa fa-edit"></i>设置中奖人</a> ');
                                    actions.push('<a class="btn btn-danger btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="randomWin(\'' + row.id + '\')"><i class="fa fa-edit"></i>随机设定中奖人</a> ');
                                }
                            }
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        }

                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        function activityBegin(id) {
            $.ajax({
                type: "post",
                url:  prefix + "/activityBegin?id="+id,
                success: function(r) {
                    $.modal.msgSuccess("活动已开始");
                }
            });
            $.modal.msgReload();
        }
        function activityEnd(id) {
            $.ajax({
                type: "post",
                url:  prefix + "/activityEnd?id="+id,
                success: function(r) {
                    $.modal.msgSuccess("活动已开奖");
                }
            });
            $.modal.msgReload();
        }
        function randomWin(id) {
            $.ajax({
                type: "post",
                url:  prefix + "/randomWin?id="+id,
                success: function(r) {
                    $.modal.msgSuccess("开奖成功");
                }
            });
            $.modal.msgReload();
        }
        function settingWin(id) {
            $.modal.open("设置中奖人", prefix+"/settingWin/"+id);
        }
    </script>
</body>
</html>